package eip.chapter5.messagefilter.mule;

import org.mule.umo.UMOFilter;
import org.mule.umo.UMOMessage;

import eip.chapter5.messagefilter.DeclarationMessage;

/**
 * This checks whether the message is between the minimum (inclusive)
 * and maximum (exclusive) amount. If this is the case the message is 
 * accepted. If not the message is rejected.
 * 
 * This is a stateless filter.
 * 
 * @author nl24167
 */
public class DeclarationAmountFilter implements UMOFilter {

	private double minAmount = Double.MIN_VALUE;
	private double maxAmount = Double.MAX_VALUE;
	
	/**
	 * Check whether we accept the message.
	 */
	public boolean accept(UMOMessage message) {
		if (message.getPayload() instanceof DeclarationMessage) {
			DeclarationMessage msg = (DeclarationMessage) message.getPayload();
			double amount = msg.getDeclarationAmount();
			if (amount >= minAmount && amount < maxAmount) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	public double getMaxAmount() {
		return maxAmount;
	}

	public void setMaxAmount(double maxAmount) {
		this.maxAmount = maxAmount;
	}

	public double getMinAmount() {
		return minAmount;
	}

	public void setMinAmount(double minAmount) {
		this.minAmount = minAmount;
	}
}
